package com.xone.xapp;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.widget.ImageView;

public class IdentifyCodeLoader {
	
	protected Context context;
	protected boolean req = false;
	
	public IdentifyCodeLoader(Context context) {
		this.context = context;
		req = false;
	}
	
	public void displayImage(final ImageView imageView) {
		if (req) {
			return;//防止频繁请求
		}
		req = true;
		new AsyncTask<String, Void, Bitmap>() {
			@Override
			protected Bitmap doInBackground(String... params) {
				if (isCancelled()) {
					return null;
				}
				if (null == params || params.length == 0) {
					return null;
				}
				return HttpUtils.getCodeImage(params[0]);
			}
			@Override
			protected void onPostExecute(Bitmap bm) {
				super.onPostExecute(bm);
				if (null != bm && null != imageView) {
					imageView.setImageBitmap(bm);
				}
				req = false;
			}
		}.execute(Constants.APP_URL + "/identifyCode.jpeg?_=" + System.currentTimeMillis());
	}

}
